#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
const int N=1e5+50;
const int M=1e6+50;
const int INF=0x3f3f3f3f;
struct Edge{
    int u,v,w;
};
vector<Edge> edges[N];
bool vis[N];
int cnt[N];
int dis[N];
int n,m,s,t;
int u,v,w;
bool spfa(int s){
    memset(vis,false,sizeof(vis));
    memset(cnt,0,sizeof(cnt));
    for(int i=1;i<=n;i++){
        dis[i]=INF;
    }
    dis[s]=0;
    vis[s]=true;
    queue<int> q;
    q.push(s);
    cnt[s]=1;
    while(!q.empty()){
        int u=q.front();
        q.pop();
        vis[u]=false;
        for(int i=0;i<edges[u].size();i++){
            int v=edges[u][i].v;
            int w=edges[u][i].w;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;
                if(!vis[v]){
                    vis[v]=true;
                    q.push(v);
                    if(++cnt[v]>n){
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
int main(void){
    scanf("%d%d%d%d",&n,&m,&s,&t);
    while(m--){
        scanf("%d%d%d",&u,&v,&w);
        edges[u].push_back(Edge{u,v,w});
        edges[v].push_back(Edge{v,u,w});
    }
    spfa(s);
    printf("%d\n",dis[t]);
    return 0;
}